The Python Workbook by Ben Stephenson

The Python Workbook by Ben Stephenson

Author:Ben Stephenson
Language: eng
Format: epub, pdf
ISBN: 9783030188733
Publisher: Springer International Publishing


Exercise 107: Reduce a Fraction to Lowest Terms

(Solved, 46 Lines)

Write a function that takes two positive integers that represent the numerator and denominator of a fraction as its only parameters. The body of the function should reduce the fraction to lowest terms and then return both the numerator and denominator of the reduced fraction as its result. For example, if the parameters passed to the function are 6 and 63 then the function should return 2 and 21. Include a main program that allows the user to enter a numerator and denominator. Then your program should display the reduced fraction.

Hint: In Exercise 79 you wrote a program for computing the greatest common divisor of two positive integers. You may find that code useful when completing this exercise.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.